﻿using System;
using System.Globalization;
using Avalonia.Data.Converters;
using Material.Icons;

namespace MusicDiary.WindowApp.Converters;

public class IconConvertor : IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                return value;
            }
            
            if (s == "Single Loop")
            {
                s = "Repeat";
            }

            if (s == "List")
            {
                s = "PlaylistPlay";
            }

            if (s == "Random")
            {
                s = "Shuffle";
            }

            if (s == "Single")
            {
                s = "Loop";
            }

            return Enum.Parse<MaterialIconKind>(s);
        }
        return value;
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        return value;
    }
}